class Solution:
    def minWindow(self, s: str, t: str) -> str:
        length, i = float("inf"), 0
        ans = ""
        counter = {}
        # 初始化计数器
        standCounter = {}
        for x in t:
            if x not in standCounter:
                standCounter[x] = 1
            else:
                standCounter[x] += 1  
        # 校验条件是否满足
        def IsCotain(counter, standCounter):
            for x, v in standCounter.items():
                if x not in counter: 
                    return False
                elif counter[x] < v:
                    return False
            return True

        # 遍历生成窗口
        for j, v in enumerate(s):
            if v not in counter:
                counter[v] = 1
            else:
                counter[v] += 1
            
            while IsCotain(counter, standCounter):
                length = min(length, j - i + 1)
                if length == (j - i + 1):
                    ans = s[i:j+1]
                counter[s[i]] -= 1
                i += 1
        
        return ans

                




